import urllib2,cookielib,re,json

done_dict={}
for i in range(28):
    print "#",
    cookie_support= urllib2.HTTPCookieProcessor(cookielib.CookieJar())
    opener = urllib2.build_opener(cookie_support,urllib2.HTTPHandler) 
    opener.addheaders=[("Host","www.baicizhan.com"),
    ("Connection","keep-alive"),
    ("Accept","application/json, text/javascript, */*; q=0.01"),
    ("X-Requested-With","XMLHttpRequest"),
    ("User-Agent","Mozilla/5.0 (Windows NT 6.3; WOW64), AppleWebKit/537.36 (KHTML, like Gecko), Chrome/30.0.1599.101 Safari/537.36"),
    ("DNT","1"),
    ("Referer","http://www.baicizhan.com/user/words/list"),
    ("Accept-Encoding","gzip,deflate,sdch"),
    ("Accept-Language","zh-CN,zh;q=0.8"),
    ("Cookie","remember_account=978750903%40qq.com; auth_token=1498928%3A8eefec4300b1f411fea46243bc63f47ca5789687; old_user=1; _jjboom-web_session=BAh7CEkiDHVzZXJfaWQGOgZFRmkDMN8WSSIPc2Vzc2lvbl9pZAY7AEZJIiVjN2VmMDA0ZDI3YWQyYzVlMDA5OTRhMGI3OGUzZTI0OQY7AFRJIhBfY3NyZl90b2tlbgY7AEZJIjFBS20xK0YydnIrUVJPMTlNZERjbC93aE4xMTAvcGYyVStuR0tlejR4a0U4PQY7AEY%3D--0ddc625112881161df5fa5304551484ffb1e393d; __utma=173264688.1443308915.1395317147.1395905918.1398334350.5; __utmb=173264688.10.10.1398334350; __utmc=173264688; __utmz=173264688.1395905918.4.2.utmcsr=baidu|utmccn=(organic),|utmcmd=organic|utmctr=%E7%99%BE%E8%AF%8D%E6%96%A9; SERVERID=4719c6c6522ae278d6cab85d90ba81a6|1398334779|1398334344")]
    html = opener.open("http://www.baicizhan.com/user/all_done_words_list?page=%d"%(i+1)).read()
    jsons = json.loads(html)
    for i in jsons['list']: done_dict[i['word']] = i['word_meaning']

print "done:",len(done_dict)
import codecs
json.dump(done_dict,codecs.open("dict/doneList.json","w",encoding='utf-8'),indent=2,ensure_ascii =False)



passed_dict={}
for i in range(8):
    print "#",
    cookie_support = urllib2.HTTPCookieProcessor(cookielib.CookieJar())
    opener = urllib2.build_opener(cookie_support,urllib2.HTTPHandler) 
    opener.addheaders =[("Host","www.baicizhan.com"),
    ("Connection","keep-alive"),
    ("Accept","application/json, text/javascript, */*; q=0.01"),
    ("X-Requested-With","XMLHttpRequest"),
    ("User-Agent","Mozilla/5.0 (Windows NT 6.3; WOW64), AppleWebKit/537.36 (KHTML, like Gecko), Chrome/30.0.1599.101 Safari/537.36"),
    ("DNT","1"),
    ("Referer","http://www.baicizhan.com/user/words/list"),
    ("Accept-Encoding","gzip,deflate,sdch"),
    ("Accept-Language","zh-CN,zh;q=0.8"),
    ("Cookie","remember_account=978750903%40qq.com; auth_token=1498928%3A8eefec4300b1f411fea46243bc63f47ca5789687; old_user=1; _jjboom-web_session=BAh7CEkiDHVzZXJfaWQGOgZFRmkDMN8WSSIPc2Vzc2lvbl9pZAY7AEZJIiVjN2VmMDA0ZDI3YWQyYzVlMDA5OTRhMGI3OGUzZTI0OQY7AFRJIhBfY3NyZl90b2tlbgY7AEZJIjFBS20xK0YydnIrUVJPMTlNZERjbC93aE4xMTAvcGYyVStuR0tlejR4a0U4PQY7AEY%3D--0ddc625112881161df5fa5304551484ffb1e393d; __utma=173264688.1443308915.1395317147.1395905918.1398334350.5; __utmb=173264688.10.10.1398334350; __utmc=173264688; __utmz=173264688.1395905918.4.2.utmcsr=baidu|utmccn=(organic),|utmcmd=organic|utmctr=%E7%99%BE%E8%AF%8D%E6%96%A9; SERVERID=4719c6c6522ae278d6cab85d90ba81a6|1398334779|1398334344")]
    html = opener.open("http://www.baicizhan.com/user/all_passed_words_list?page=%d"%(i+1)).read()
    jsons = json.loads(html)
    for i in jsons['list']: passed_dict[i['word']] = i['word_meaning']
print "passed:",len(passed_dict)
import codecs
json.dump(passed_dict,codecs.open("dict/passedList.json","w",encoding='utf-8'),indent=2,ensure_ascii =False)
